package com.base.social.auth.factory;

import com.base.social.auth.request.AuthWeChatMini;
import com.base.social.cache.AuthStateCache;
import com.base.social.config.AuthConfig;
import com.base.social.auth.Auth;
import com.base.social.auth.AuthFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 微信小程序授权
 */
public class WechatMiniAuthFactory implements AuthFactory {

    /**
     * 客户端id：对应各平台的appKey
     */
    private String clientId;

    /**
     * 客户端Secret：对应各平台的appSecret
     */
    private String clientSecret;


    /**
     * 微信响应类型 默认code
     */
    private String responseType;

    /**
     * 微信授权作用域
     */
    private String scope;

    private static class Holder{
        private static final WechatMiniAuthFactory INSTANCE = new WechatMiniAuthFactory();
    }

    //实例化
    public static WechatMiniAuthFactory build(){
        return Holder.INSTANCE;
    }

    @Override
    public Auth instance(AuthConfig authConfig, AuthStateCache authStateCache) {
//        authConfig.setClientSecret(this.clientSecret);
//        authConfig.setClientId(this.clientId);
//        authConfig.setResponseType(this.responseType);
//        authConfig.setScope(scope);
        if (authStateCache != null) {
            return new AuthWeChatMini(authConfig, authStateCache);
        }
        return new AuthWeChatMini(authConfig);
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public void setResponseType(String responseType) {
        this.responseType = responseType;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getScope() {
        return scope;
    }

    public String getResponseType() {
        return responseType;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public String getClientId() {
        return clientId;
    }

}
